package com.lcx.plugin.dto;

import cn.hutool.core.util.StrUtil;
import com.lcx.plugin.tool.CaseFormatUtil;
import lombok.Data;

import java.util.Objects;

/**
 * @author daxiong
 * @date 2023/6/14 下午2:34
 */
@Data
public class ExcelDbFiledDTO {

    private String field;
    private String name;
    private String type;
    private String length;
    private String must;
    private String memo;
    /**
     * 以下是索引属性
     */
    private Integer indexType;
    private String indexName;
    private String indexNote;

    private String fieldUnderline;

    public void init() {
        this.fieldUnderline = CaseFormatUtil.camel2UnderScore(this.field);

        if (this.isIndex()) {
            // 该字段是索引字段
            if (StrUtil.isBlank(indexName)) {
                // 默认索引名是字段名
                this.indexName = fieldUnderline;
            }
            if (Objects.isNull(indexType)) {
                // 默认索引类型是普通索引
                this.indexType = 2;
            }
        }
    }

    public boolean isIndex() {
        return Objects.nonNull(indexType) || StrUtil.isNotBlank(indexName) || StrUtil.isNotBlank(indexNote);
    }

}
